using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using SharpPieces.Web.Controls;
using System.Text;

namespace SharpPieces.DemoApp
{

    /// <summary>
    /// The Extended DropDownList Functionality page.
    /// </summary>
    public partial class ExtendedDropDownListFunctionality : System.Web.UI.Page
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //populate combobox

                this.ddl.ExtendedItems.Add("Choose an item...");
                this.ddl.ExtendedItems.Add(new ExtendedListItem("Monitor", "12", true, ListItemGroupingType.New,
                    "Computers"));

                this.ddl.ExtendedItems.Add(new ExtendedListItem("Mouse", "13", ListItemGroupingType.Inherit));
                this.ddl.ExtendedItems.Add(new ExtendedListItem("Keyboard", "14", ListItemGroupingType.Inherit));

                this.ddl.ExtendedItems.Add(new ExtendedListItem("iPhone", "21", true, ListItemGroupingType.New,
                    "Phones"));
                this.ddl.ExtendedItems.Add(new ExtendedListItem("gPhone", "22", ListItemGroupingType.Inherit));
                this.ddl.ExtendedItems.Add(new ExtendedListItem("HTC S730", "23", ListItemGroupingType.Inherit));

                this.ddl.ExtendedItems[1].Attributes.Add("key1", "val1");
                this.ddl.ExtendedItems[2].Attributes.Add("key2", "val2");

                this.ddl.Items.FindByValue("23").Selected = true;
            }

            this.btnPostback.Click += new EventHandler(btnPostback_Click);
        }

        void btnPostback_Click(object sender, EventArgs e)
        {
            StringBuilder sbGroups = new StringBuilder();
            sbGroups.AppendFormat("selected item group for {0}: {1}<br />", 
                ddl.ID, ddl.SelectedGroup);
            sbGroups.AppendFormat("selected item group for {0}: {1}<br />", 
                ExtendedDropDownList1.ID,
                ExtendedDropDownList1.SelectedGroup);

            this.lblSelGroup.Text = sbGroups.ToString();
        }

    }

}
